/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.merak.core.web.tags;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

import org.merak.core.web.mvc.FrontController;
import org.merak.core.web.mvc.MVCManager;

@SuppressWarnings("serial")
public class Business extends TagSupport  {

    //~ Attributes ///////////////////////////////////////////////////////////////
	//****************************************************************************
	private String name   = null;
	private String params = null;

	//~ Constructors /////////////////////////////////////////////////////////////
	//****************************************************************************
	public Business() {
		super();
	}
	//****************************************************************************
	@Override
	public int doStartTag() throws JspException {

		try {
			// Required attributes
			StringBuffer buffer = new StringBuffer()
			.append(FrontController.getName())
			.append('?')
			.append(MVCManager.getBusinessParameter())
			.append('=')
			.append(this.name);

			// Optional Attributes
			if (this.params != null) {
				buffer.append('&').append(this.params);
			}

			// Render the tag
			this.pageContext.getOut().write(buffer.toString());
		}
		catch(IOException e) {
			throw new JspTagException("IO Error: " + e.getMessage());
		}
		return Tag.SKIP_BODY;

	}
	//****************************************************************************
	public String getName() {
		return this.name;
	}
	//****************************************************************************
	public void setName(String name) {
		this.name = name;
	}
	//****************************************************************************
	public String getParams() {
		return this.params;
	}
	//****************************************************************************
	public void setParams(String params) {
		this.params = params;
	}
	//****************************************************************************
}
